/**
 * ReportGear(2011)
 */
package com.reportgear.core.api;

/**
 * 名称化对象
 * 
 * @version 1.0 2011-4-26
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class NameObject<T> extends BaseObject implements Nameable {
	protected String name;
	protected T object;

	public NameObject() {
	}

	public NameObject(String name, T object) {
		setName(name);
		setObject(object);
	}

	@Override
	public String getName() {
		return this.name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	public T getObject() {
		return this.object;
	}

	public void setObject(T object) {
		this.object = object;
	}

	public String toString() {
		return "名称:" + getName() + "\t对象:" + getObject();
	}

	@SuppressWarnings("unchecked")
	@Override
	public NameObject<T> clone() {
		NameObject<T> nameObject = (NameObject<T>) super.clone();
		
		T object = this.getObject();
		
		if (BaseObject.class.isAssignableFrom(object.getClass())) {
			nameObject.object = (T) ((BaseObject) nameObject.object).clone();
		}

		return nameObject;
	}
}